package com.google.code.flexmetavalidator.reflection
{
	import flash.utils.Dictionary;

	public class VariableInfo
	{
		public static function fromXmlDescriptor(desc : XML) : VariableInfo
		{
			var retInfo : VariableInfo = new VariableInfo();
			retInfo.name = String(desc.@name);
			retInfo.type = String(desc.@type);
			retInfo.metaTags = new Array();
			
			var metaDataXList : XMLList = desc.metadata;
			for each (var mdxml : XML in metaDataXList)
			{
				retInfo.metaTags.push(MetaTag.fromXmlDescriptor(mdxml));
			}
			
			return retInfo;
		}
		
		
		public var name : String;
		public var type : String;
		public var metaTags : Array;
		
		public function get metaTagsDictionary() : Dictionary
		{
			var retDictionary : Dictionary = new Dictionary();
			for each (var metaTag : MetaTag in metaTags)
			{
				if (retDictionary[metaTag.name] != null)
				{
					var metaParameters : Array = retDictionary[metaTag.name].metaParameters;
					var newMetaParameters : Array = metaParameters.concat(metaTag.metaParameters);
					retDictionary[metaTag.name].metaParameters = newMetaParameters;
				}
				else
				{
					retDictionary[metaTag.name] = metaTag;
				}
			}
			return retDictionary;
		}
		
	}
}